﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using kit206_A2.controller;
using kit206_A2.model;
using kit206_A2.database_controller;
using System.Collections.ObjectModel;

namespace kit206_A2.view
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        private const string STAFF_LIST_KEY = "staffList";
        private staff_list_controller staff_basic;
        private staff SelectedStaff { get; set; }
        public ObservableCollection<class_event> SelectedEvents { get; set; }
        public MainWindow()
        {
            InitializeComponent();
            SelectedEvents = new ObservableCollection<class_event>();
        }
       
        private void staffListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                var item = (ListBox)sender;
                var list = (staff)item.SelectedItem;
 
                var staff = staff_list_controller.get_staff_detail(list.ID);

                staff_list_controller.loadStaff_teaching(staff);
                SelectedEvents.Clear();
                foreach (var consultation in staff.Consultations)
                {
                    SelectedEvents.Add(consultation);
                }
                SelectedStaff = staff;
            }
        }


        private void sampleTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                //sampleButton_Click(sender, e);
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(" Clicked the button... " );
        }

        //input filter
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            var temp_input = input_value.Text; //return input box value

            //MessageBox.Show("***: " +  temp_input);  //output testing
            staff_list_controller.inputFilter(temp_input);

        }

        //category filter
        private void category_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //var item = (ComboBox)sender;
            //var list = (staff)item.SelectedItem;

            if (e.RemovedItems.Count > 0)
            {
                //e.AddedItems[0].GetType() returns category type
                //e.AddedItems[0] returns value

                //MessageBox.Show("***: " + e.AddedItems[0].GetType());
                var temp_category = e.AddedItems[0];

                staff_list_controller.Filter((Category)temp_category);

                //MessageBox.Show("Dropdown list used to select: " + e.AddedItems[0]);
            }
            //MessageBox.Show("***: " +sender + e );
        }

        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            staff_basic = (staff_list_controller)(Application.Current.FindResource(STAFF_LIST_KEY) as ObjectDataProvider).ObjectInstance;
        }
    }
}
